package lazy.sql;

import java.util.List;
import lazy.util.StringUtils;

public class LogicColumnOperatorValue {
	private SqlLogic sqlLogic;
	private String tableAlias;
	private String column;
	private SqlOperator sqlOperator;
	private Object value;
	private List<LogicColumnOperatorValue> subSelectList;
	
	public LogicColumnOperatorValue(SqlLogic sqlLogic, String tableAlias, String column, SqlOperator sqlOperator, Object value) {
		this.sqlLogic = sqlLogic;
		if(StringUtils.hasText(tableAlias)) this.tableAlias = tableAlias.toUpperCase();
		if(StringUtils.hasText(column)) this.column = column.toUpperCase();
		this.sqlOperator = sqlOperator;
		this.value = value;
	}
	public LogicColumnOperatorValue(SqlLogic sqlLogic, String column, SqlOperator sqlOperator, Object value) {
		this(sqlLogic, null, column, sqlOperator, value);
	}
	public LogicColumnOperatorValue(String column, SqlOperator sqlOperator, Object value) {
		this(null, column, sqlOperator, value);
	}
	public LogicColumnOperatorValue(SqlLogic sqlLogic, List<LogicColumnOperatorValue> subSelectLogicColumnOperatorValue) {
		if(subSelectLogicColumnOperatorValue!=null && subSelectLogicColumnOperatorValue.size()>0) {
			LogicColumnOperatorValue tmp = subSelectLogicColumnOperatorValue.remove(0);
			this.sqlLogic = sqlLogic!=null?sqlLogic:SqlLogic.AND;
			if(StringUtils.hasText(tmp.tableAlias)) this.tableAlias = tmp.tableAlias.toUpperCase();
			if(StringUtils.hasText(tmp.column)) this.column = tmp.column.toUpperCase();
			this.sqlOperator = tmp.sqlOperator;
			this.value = tmp.value;
			this.subSelectList = subSelectLogicColumnOperatorValue;
		}
	}
	LogicColumnOperatorValue(DefaultWhere defaultWhere, String column, Object value) {
		this(
			defaultWhere.sqlLogic()!=null?defaultWhere.sqlLogic():SqlLogic.AND,
			defaultWhere.tableAlias(),
			StringUtils.hasText(defaultWhere.column())?defaultWhere.column():column,
			defaultWhere.sqlOperator()!=null?defaultWhere.sqlOperator():SqlOperator.EQUAL,
			value
		);
	}
	public SqlLogic getSqlLogic() {
		return sqlLogic;
	}
	public void setSqlLogic(SqlLogic sqlLogic) {
		this.sqlLogic = sqlLogic;
	}
	public String getColumn() {
		return column;
	}
	public void setColumn(String column) {
		if(StringUtils.hasText(column)) this.column = column.toUpperCase();
	}
	public SqlOperator getSqlOperator() {
		return sqlOperator;
	}
	public void setSqlOperator(SqlOperator sqlOperator) {
		this.sqlOperator = sqlOperator;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	public String getTableAlias() {
		return tableAlias;
	}
	public void setTableAlias(String tableAlias) {
		if(StringUtils.hasText(tableAlias)) this.tableAlias = tableAlias.toUpperCase();
	}
	public List<LogicColumnOperatorValue> getSubSelectList() {
		return subSelectList;
	}
	public void setSubSelectList(List<LogicColumnOperatorValue> subSelectList) {
		this.subSelectList = subSelectList;
	}
	public static void main(String[] args) {
		
	}
}
